package com.design.pattern;

public class AbstractFactoryPattern {
    public static void main(String[] args){
        ColorFactory color = (ColorFactory) FactoryProducer.getFactory("color");
        ShapeFactory shape = (ShapeFactory) FactoryProducer.getFactory("shape");
        color.getColor("red").draw();
        shape.getShape("Circle").draw();
    }
}

interface Color{
    void draw();
}

class Red implements Color{

    @Override
    public void draw() {
        System.out.println("Color Red: draw().");
    }
}
class Green implements Color{

    @Override
    public void draw() {
        System.out.println("Color Green: draw().");
    }
}
class Blue implements Color{

    @Override
    public void draw() {
        System.out.println("Color Blue: draw().");
    }
}

class ColorFactory extends AbstractFactory{
 public static Color getColor(String colorType){
     if(colorType == null){
         return null;
     }
     if(colorType.equalsIgnoreCase("Red")){
         return new Red();
     } else if(colorType.equalsIgnoreCase("Blue")){
         return new Blue();
     } else if(colorType.equalsIgnoreCase("Green")){
         return new Green();
     }
     return null;
 }
}
abstract class AbstractFactory{
    public static Shape getShape(String shapeType){
        return  null;
    }
    public static Color getColor(String colorType){
        return null;
    }
}

class FactoryProducer{
    public static AbstractFactory getFactory(String factoryType){
        if(factoryType == null){
            return null;
        }
        if(factoryType.equalsIgnoreCase("Color")){
            return new ColorFactory();
        } else if(factoryType.equalsIgnoreCase("Shape")){
            return new ShapeFactory();
        }
        return null;
    }
}